import { createStore } from 'vuex'

export default createStore({
  state: {
    user_info: {
      user_id: localStorage.getItem('userId') || 0,
      user_identifier: localStorage.getItem('userRole')||0, //用户身份，0=未登录，1=管理员，2=租客，3=房东，
      user_avatar: localStorage.getItem('userAvatar')||'',
    }, //用户信息
  },
  getters: {
    // 获取当前用户信息
    getUserIdentity(state) {
      return state.user_info.user_identifier
    },
    // 检查用户是否登录
    checkUserLogin(state) {
      return state.user_info.user_identifier != 0
    },
    // 获取用户id
    getUserId(state) {
      return state.user_info.user_id
    },
    // 获取用户头像
    getUserAvatar(state) {
      return state.user_info.user_avatar
    },

  },
  mutations: {
    // 设置当前用户身份
    setUserIdentity(state, identity) {
      state.user_info.user_identifier = identity
    },
    // 设置当前用户id
    setUserId(state, id) {
      state.user_info.user_id = id
    },
    // 设置当前用户头像
    setUserAvatar(state, avatar) {
      state.user_info.user_avatar = avatar
    },
  },
  actions: {
  },
  modules: {
  }
})
